// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_delete_ok.java

package ecommerce.crm;

import include.get_sql.getInsertSql;
import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class check_delete_ok extends HttpServlet
{

	public check_delete_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		try
		{
			HttpSession dbSession = request.getSession();
			JspFactory _jspxFactory = JspFactory.getDefaultFactory();
			javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
			javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
			HttpSession session = request.getSession();
			nseer_db_backup1 crm_db = new nseer_db_backup1(dbApplication);
			nseer_db_backup1 crm_db1 = new nseer_db_backup1(dbApplication);
			ValidataNumber validata = new ValidataNumber();
			ValidataTag vt = new ValidataTag();
			counter count = new counter(dbApplication);
			getInsertSql getInsertSql = new getInsertSql();
			if (crm_db.conn((String)dbSession.getAttribute("unit_db_name")) && crm_db1.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String config_id = request.getParameter("config_id");
				String customer_ID = request.getParameter("customer_ID");
				String choice = request.getParameter("choice");
				String bodyd = new String(request.getParameter("opinion").getBytes("UTF-8"), "UTF-8");
				String opinion = exchange.toHtml(bodyd);
				String checker_ID = request.getParameter("checker_ID");
				String checker = request.getParameter("checker");
				String check_time = request.getParameter("check_time");
				String lately_change_time = request.getParameter("lately_change_time");
				String file_change_amount = request.getParameter("file_change_amount");
				int change_amount = Integer.parseInt(file_change_amount) + 1;
				String column_group = getInsertSql.sql((String)dbSession.getAttribute("unit_db_name"), "crm_file");
				String sql6 = (new StringBuilder("select * from ecommerce_workflow where object_ID='")).append(customer_ID).append("' and ((check_tag='0' and config_id<'").append(config_id).append("') or (check_tag='1' and config_id='").append(config_id).append("'))").toString();
				ResultSet rs6 = crm_db.executeQuery(sql6);
				if (!rs6.next() && vt.validata((String)session.getAttribute("unit_db_name"), "crm_file", "customer_ID", customer_ID, "excel_tag").equals("1"))
				{
					if (choice != null)
					{
						sql6 = (new StringBuilder("select * from ecommerce_workflow where object_ID='")).append(customer_ID).append("' and config_id<'").append(config_id).append("'").toString();
						rs6 = crm_db.executeQuery(sql6);
						if (!rs6.next())
						{
							String sqloo = (new StringBuilder("select * from crm_file where customer_ID='")).append(customer_ID).append("'").toString();
							ResultSet rs8 = crm_db.executeQuery(sqloo);
							if (rs8.next())
							{
								String sqll = (new StringBuilder("insert into crm_file_dig(CHAIN_ID,CHAIN_NAME,CUSTOMER_ID,CUSTOMER_NAME,CUSTOMER_NICK,CUSTOMER_ADDRESS,CUSTOMER_CLASS,TYPE,CUSTOMER_BANK,CUSTOMER_ACCOUNT,CUSTOMER_WEB,CUSTOMER_TEL1,CUSTOMER_TEL2,CUSTOMER_EMAIL,CUSTOMER_FAX,CUSTOMER_POSTCODE,CONTACT_PERSON1,CONTACT_PERSON1_DEPARTMENT,CONTACT_PERSON1_DUTY,CONTACT_PERSON1_SEX,CONTACT_PERSON1_OFFICE_TEL,CONTACT_PERSON1_HOME_TEL,CONTACT_PERSON1_MOBILE,CONTACT_PERSON1_FAX,CONTACT_PERSON1_EMAIL,CONTACT_PERSON1_FAVORITE,CONTACT_PERSON2,CONTACT_PERSON2_DEPARTMENT,CONTACT_PERSON2_DUTY,CONTACT_PERSON2_SEX,CONTACT_PERSON2_OFFICE_TEL,CONTACT_PERSON2_HOME_TEL,CONTACT_PERSON2_MOBILE,CONTACT_PERSON2_FAX,CONTACT_PERSON2_EMAIL,CONTACT_PERSON2_FAVORITE,INVOICE_INFO,DEMAND,REMARK,CHECK_TAG,CONTACT_AMOUNT,ACHIEVEMENT_SUM,ATTACHMENT_NAME,TRADE_AMOUNT,RETURN_SUM,RETURN_AMOUNT,GATHER_PERIOD_SUM,GATHER_PERIOD_AVERAGE,FILE_CHANGE_AMOUNT,GATHER_PERIOD_LIMIT,GATHER_SUM_LIMIT,CONTACT_PERIOD_LIMIT,USED_CUSTOMER_NAME,REGISTER,CHECKER,CHANGER,REGISTER_ID,CHECKER_ID,CHANGER_ID,REGISTER_TIME,CHECK_TIME,CHANGE_TIME,LATELY_CHANGE_TIME,LATELY_TRADE_TIME,LATELY_CONTACT_TIME,DELETE_TIME,RECOVERY_TIME,SALES_NAME,SALES_ID,MODIFY_TAG,EXCEL_TAG,REMIND_CONTACT_TAG,REMIND_GATHER_TAG,REMIND_RETURN_TAG,OPINION) values('")).append(rs8.getString("CHAIN_ID")).append("','").append(rs8.getString("CHAIN_NAME")).append("','").append(rs8.getString("CUSTOMER_ID")).append("','").append(rs8.getString("CUSTOMER_NAME")).append("','").append(rs8.getString("CUSTOMER_NICK")).append("','").append(rs8.getString("CUSTOMER_ADDRESS")).append("','").append(rs8.getString("CUSTOMER_CLASS")).append("','").append(rs8.getString("TYPE")).append("','").append(rs8.getString("CUSTOMER_BANK")).append("','").append(rs8.getString("CUSTOMER_ACCOUNT")).append("','").append(rs8.getString("CUSTOMER_WEB")).append("','").append(rs8.getString("CUSTOMER_TEL1")).append("','").append(rs8.getString("CUSTOMER_TEL2")).append("','").append(rs8.getString("CUSTOMER_EMAIL")).append("','").append(rs8.getString("CUSTOMER_FAX")).append("','").append(rs8.getString("CUSTOMER_POSTCODE")).append("','").append(rs8.getString("CONTACT_PERSON1")).append("','").append(rs8.getString("CONTACT_PERSON1_DEPARTMENT")).append("','").append(rs8.getString("CONTACT_PERSON1_DUTY")).append("','").append(rs8.getString("CONTACT_PERSON1_SEX")).append("','").append(rs8.getString("CONTACT_PERSON1_OFFICE_TEL")).append("','").append(rs8.getString("CONTACT_PERSON1_HOME_TEL")).append("','").append(rs8.getString("CONTACT_PERSON1_MOBILE")).append("','").append(rs8.getString("CONTACT_PERSON1_FAX")).append("','").append(rs8.getString("CONTACT_PERSON1_EMAIL")).append("','").append(rs8.getString("CONTACT_PERSON1_FAVORITE")).append("','").append(rs8.getString("CONTACT_PERSON2")).append("','").append(rs8.getString("CONTACT_PERSON2_DEPARTMENT")).append("','").append(rs8.getString("CONTACT_PERSON2_DUTY")).append("','").append(rs8.getString("CONTACT_PERSON2_SEX")).append("','").append(rs8.getString("CONTACT_PERSON2_OFFICE_TEL")).append("','").append(rs8.getString("CONTACT_PERSON2_HOME_TEL")).append("','").append(rs8.getString("CONTACT_PERSON2_MOBILE")).append("','").append(rs8.getString("CONTACT_PERSON2_FAX")).append("','").append(rs8.getString("CONTACT_PERSON2_EMAIL")).append("','").append(rs8.getString("CONTACT_PERSON2_FAVORITE")).append("','").append(rs8.getString("INVOICE_INFO")).append("','").append(rs8.getString("DEMAND")).append("','").append(rs8.getString("REMARK")).append("','").append(rs8.getString("CHECK_TAG")).append("','").append(rs8.getString("CONTACT_AMOUNT")).append("','").append(rs8.getString("ACHIEVEMENT_SUM")).append("','").append(rs8.getString("ATTACHMENT_NAME")).append("','").append(rs8.getString("TRADE_AMOUNT")).append("','").append(rs8.getString("RETURN_SUM")).append("','").append(rs8.getString("RETURN_AMOUNT")).append("','").append(rs8.getString("GATHER_PERIOD_SUM")).append("','").append(rs8.getString("GATHER_PERIOD_AVERAGE")).append("','").append(rs8.getString("FILE_CHANGE_AMOUNT")).append("','").append(rs8.getString("GATHER_PERIOD_LIMIT")).append("','").append(rs8.getString("GATHER_SUM_LIMIT")).append("','").append(rs8.getString("CONTACT_PERIOD_LIMIT")).append("','").append(rs8.getString("USED_CUSTOMER_NAME")).append("','").append(rs8.getString("REGISTER")).append("','").append(rs8.getString("CHECKER")).append("','").append(rs8.getString("CHANGER")).append("','").append(rs8.getString("REGISTER_ID")).append("','").append(rs8.getString("CHECKER_ID")).append("','").append(rs8.getString("CHANGER_ID")).append("','").append(rs8.getString("REGISTER_TIME")).append("','").append(rs8.getString("CHECK_TIME")).append("','").append(rs8.getString("CHANGE_TIME")).append("','").append(rs8.getString("LATELY_CHANGE_TIME")).append("','").append(rs8.getString("LATELY_TRADE_TIME")).append("','").append(rs8.getString("LATELY_CONTACT_TIME")).append("','").append(rs8.getString("DELETE_TIME")).append("','").append(rs8.getString("RECOVERY_TIME")).append("','").append(rs8.getString("SALES_NAME")).append("','").append(rs8.getString("SALES_ID")).append("','").append(rs8.getString("MODIFY_TAG")).append("','").append(rs8.getString("EXCEL_TAG")).append("','").append(rs8.getString("REMIND_CONTACT_TAG")).append("','").append(rs8.getString("REMIND_GATHER_TAG")).append("','").append(rs8.getString("REMIND_RETURN_TAG")).append("','").append(rs8.getString("OPINION")).append("')").toString();
								crm_db.executeUpdate(sqll);
							}
						}
						if (choice.equals(""))
						{
							String sql = (new StringBuilder("update crm_file set opinion='")).append(opinion).append("',excel_tag='9' where customer_ID='").append(customer_ID).append("'").toString();
							crm_db.executeUpdate(sql);
							sql = (new StringBuilder("update ecommerce_workflow set check_tag='9',checker_ID='")).append(checker_ID).append("',checker='").append(checker).append("',check_time='").append(check_time).append("' where object_ID='").append(customer_ID).append("' and config_id='").append(config_id).append("'").toString();
							crm_db.executeUpdate(sql);
						} else
						{
							sql6 = (new StringBuilder("select * from ecommerce_workflow where object_ID='")).append(customer_ID).append("' and config_id<'").append(config_id).append("' and config_id>='").append(choice).append("'").toString();
							String sql;
							for (rs6 = crm_db.executeQuery(sql6); rs6.next(); crm_db1.executeUpdate(sql))
								sql = (new StringBuilder("update ecommerce_workflow set check_tag='0' where id='")).append(rs6.getString("id")).append("'").toString();

						}
						response.sendRedirect("ecommerce/crm/check_delete_ok_a.jsp");
					} else
					{
						response.sendRedirect((new StringBuilder("ecommerce/crm/check_delete_ok_b.jsp?customer_ID=")).append(customer_ID).append("&config_id=").append(config_id).toString());
					}
				} else
				{
					response.sendRedirect("ecommerce/crm/check_delete_ok_c.jsp");
				}
				crm_db.commit();
				crm_db1.commit();
				crm_db.close();
				crm_db1.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
